using Microsoft.Practices.ObjectBuilder2;

namespace Common.Unity.Extensions
{
	public static class IBuilderContextExtensions
	{
		public static BuilderPolicyInterface GetEnsuredPolicy<BuilderPolicyInterface,BuilderPolicyType>( this IBuilderContext context ) where BuilderPolicyInterface : IBuilderPolicy where BuilderPolicyType : class, BuilderPolicyInterface, new()
		{
			BuilderPolicyInterface result =
				context.Policies.GetEnsured<BuilderPolicyInterface, BuilderPolicyType>( context.BuildKey );
			return result;
		}

		/*public static object GetBuildSource( this IBuilderContext context )
		{
			IBuildSourcePolicy policy = context.PersistentPolicies.Get<IBuildSourcePolicy>( null, true );
			object result = policy != null ? policy.Source : null;
			return result;
		}

		public static void SetBuildSource( this IBuilderContext context, object source )
		{
			context.PersistentPolicies.ClearDefault<IBuildSourcePolicy>();
			if ( source != null )
			{
				context.PersistentPolicies.SetDefault<IBuildSourcePolicy>( new BuildSourcePolicy( source ) );
			}
		}*/

	}
}